<!-- 个人中心 -->
<template>
	<view class="personal-wrap">
		<view class="user-top">
			<view class="u-t-info">
				<view class="u-t-i-l">
					<img v-if="personalInfo.avatar" :src="`${$imgUrl}${personalInfo.avatar}`" mode="scaleToFill" alt="">
					<img v-else src="/static/images/user/icon_u_avater_default.png" mode="scaleToFill" alt="">
				</view>
				<view class="u-t-i-c">
					<view class="i-name">{{ personalInfo.realname||'暂无' }}</view>
					<view>完善簡歷信息，有更多機會哦～</view>
				</view>
				<view class="u-t-i-r" @tap="handleUserInfo()">
					<img src="/static/images/boss/icon_b_arrow_right.png" mode="scaleToFill" alt="">
				</view>
			</view>
			<view class="u-t-btn">
				<view class="u-t-b-l">
					<img src="/static/images/user/icon_u_file.png" mode="scaleToFill" alt="">
				</view>
				<view class="u-t-b-c" @tap="handleDMS()">
					<view>待面試</view>
					<view>{{ interview_count }}</view>
				</view>
				<view class="u-t-b-r" @tap="handleDMS()">
					<img src="/static/images/user/icon_u_arrow_right_white.png" mode="scaleToFill" alt="">
				</view>
			</view>
		</view>
		<view class="online-info top">
			<view class="file-title" @tap="jumpZXJL()">
				<view class="f-t-l">
					<img src="/static/images/user/icon_u_id_card.png" mode="scaleToFill" alt="">
					<view>在線簡歷</view>
				</view>
				<view class="f-t-r">
					<img src="/static/images/user/icon_u_edit.png" mode="scaleToFill" alt="">
				</view>
			</view>
			<view class="file-box" v-if="hasJL==1">
				<view class="file-row">
					<view class="file-r-item f-r-i-l">
						<img src="/static/images/user/icon_u_gray_gw.png" mode="scaleToFill" alt="">
						<view>{{ personalInfo.work_experience?personalInfo.work_experience.name:'--' }}經驗 · {{ personalInfo.age }}歲 · {{ personalInfo.education_level?personalInfo.education_level.name:'--' }}</view>
					</view>
					<view class="file-r-item">
						<img src="/static/images/user/icon_u_gray_sj.png" mode="scaleToFill" alt="" style="width: 14px;">
						<view>{{ personalInfo.mobile }}</view>
					</view>
				</view>
				<view class="file-row">
					<img src="/static/images/user/icon_u_gray_dp.png" mode="scaleToFill" alt="">
					<view v-if="biographicalInfo.job_intention.length>0">期望月薪：{{ `${biographicalInfo.job_intention[0].expect_salary_min}元-${biographicalInfo.job_intention[0].expect_salary_max}元` }}</view>
					<view v-else>期望月薪：--</view>
				</view>
				<view class="file-row">
					<img src="/static/images/user/icon_u_gray_gz.png" mode="scaleToFill" alt="">
					<view v-if="biographicalInfo.job_intention.length>0">期望職位：{{ biographicalInfo.job_intention[0].expect_job_name }}</view>
					<view v-else>期望職位：--</view>
				</view>
				<view class="file-row-b" @tap="jumpZXJL()">
					<view>查看更多</view>
					<img src="/static/images/user/icon_b_arrow_gray_right.png" mode="scaleToFill" alt="">
				</view>
			</view>
			<view class="file-no" v-else>
				<img src="/static/images/user/icon_u_no_file.png" mode="scaleToFill" alt="">
				<view>快速創建妳的在線簡歷吧～</view>
			</view>
		</view>

		<view class="online-info">
			<view class="file-title">
				<view class="f-t-l">
					<img src="/static/images/user/icon_u_file_ex.png" mode="scaleToFill" alt="">
					<view>附件簡歷</view>
				</view>
				<view class="f-t-r">
				</view>
			</view>
			<view class="file-jl-list">
				<view class="file-jl-li" :class="0==index?'top':''" v-for="(item,index) in jlList" :key="index">
					<view class="f-j-l-l">
						<img src="/static/images/user/icon_u_jl.png" mode="scaleToFill" alt="">
						<view>{{ item.name }}.{{ item.file_ext|filterFileType }}</view>
					</view>
					<img @tap="handleJlDelete(item,index)" src="/static/images/user/icon_u_more.png" mode="scaleToFill" alt="">
				</view>
			</view>
			<view class="file-jl-no" @tap="uploadFiles()">
				<img src="/static/images/user/icon_u_add.png" mode="scaleToFill" alt="">
				<view>上傳簡歷</view>
			</view>
		</view>
		
		<view class="online-info" @tap="handleResume()">
			<view class="file-title">
				<view class="f-t-l">
					<img src="/static/images/user/icon_u_card.png" mode="scaleToFill" alt="">
					<view>個人資料證件</view>
				</view>
				<view class="f-t-r icon_a_r">
					<img src="/static/images/boss/icon_b_arrow_right.png" mode="scaleToFill" alt="">
				</view>
			</view>
		</view>
		<view class="login-btn" @tap="handleLoginOut()">退出賬號</view>
	</view>
</template>

<script>
import { userMyResume, resumeResultFiles,resumeUploadResume,resumeDeleteResume,userLogout } from '../../utils/userApi'
export default {
	components: {
	},
	data() {
		return {
			scrollTop: 0,
			hasJL:0,//是否有简历
			hasFile:false,//是否有附件
			jlIndex:0,
			jlList:[
				{id:1,name:'個人簡歷01.docx'},
				{id:2,name:'個人簡歷02.docx'},
			],
			biographicalInfo:{},
			userInfo:{},
			interview_count:0,
			file_list:[],
			file_name:'',
			personalInfo:{},
		}
	},
	filters:{
		filterFileType(val){
			if(val){
				return val.split('/')[val.split('/').length-1]
			}
		}
	},
	computed: {
	},
	// 下拉刷新
	onPullDownRefresh() {
	},
	onPageScroll(e) {
		this.scrollTop = e.scrollTop
	},
	onShow() {
		this.userInfo=uni.getStorageSync('userInfo')
		this.getUserMyResume()
		this.getResumeResultFiles()
	},
	methods: {
		handleResume(){//個人資料證件
			uni.navigateTo({ url: '/pages/boss/user/certificate'})
		},
		jumpZXJL(){//在線簡歷
			uni.navigateTo({ url: '/pages/boss/user/onlineResume'})
		},
		handleDMS(){//待面試
			uni.navigateTo({ url: '/pages/boss/user/waitingInterview'})
		},
    uploadFiles(){
      let that=this
      uni.chooseFile({
        count:1,
        extension: ['.pdf'],//文件類型
        success:res=>{
					this.file_name=res.tempFiles[0].name
          let tempFiles = res.tempFiles
          let tempFilePaths = res.tempFilePaths
          uni.uploadFile({
            url: `${that.$imgUrl}/api/common/upload`,
            filePath: tempFilePaths[0],
            header: {
              token: uni.getStorageSync('token')
            },
            name: "file",
          }).then(res => {
            let data = JSON.parse(res.data)
            if(data.code==1){
							let upload_file_url=data.data.fullurl
							this.uploadResume(upload_file_url)
            }else{
              uni.showToast({
                icon:'none',
                title: data.msg||'系統異常'
              })
            }
          })
        }
      })
    },
		async uploadResume(url){
			let file_name=this.file_name.split('.')
			let res=await resumeUploadResume({
				file:url,
				name:file_name[0],
				resume_id:this.biographicalInfo.id
			})
			if(res.code==1){
				uni.showToast({
          icon:'none',
          title: '上传成功'
        })
				this.getResumeResultFiles()
			}else{
				uni.showToast({
          icon:'none',
          title: res.msg||'系統異常'
        })
			}
		},
		handleUserInfo(){
			uni.navigateTo({ url: '/pages/boss/user/info'})
		},
		async getResumeResultFiles(){
			let res=await resumeResultFiles({id:this.biographicalInfo.id})
			if(res.code==1){
				this.jlList=res.data
			}else{
				uni.showToast({
          icon:'none',
          title: res.msg||'系統異常'
        })
			}
		},
		async getUserMyResume(){
			let res=await userMyResume()
			if(res.code==1){
				this.interview_count=res.data.interview_count
				if(res.data.resume.id){
					this.biographicalInfo=res.data.resume
					this.personalInfo=res.data.resume.personal
				}
				this.hasJL=res.data.resume.id?1:0
			}else{
				uni.showToast({
          icon:'none',
          title: res.msg||'系統異常'
        })
			}
		},
		handleJlDelete(item,index){
			uni.showActionSheet({
				itemList: ['删除'],
				success: ({ tapIndex }) => {
					if(tapIndex==0){
						this.deleteUploadFile(item,index)
					}
				},
				fail: (error) => {}
			})
		},
		async deleteUploadFile(item,index){
			let res=await resumeDeleteResume({resume_id:item.id})
			if(res.code==1){
				uni.showToast({
          icon:'none',
          title: '上传成功'
        })
				this.getResumeResultFiles()
			}else{
				uni.showToast({
          icon:'none',
          title: res.msg||'系統異常'
        })
			}
		},
		handleLoginOut(){
			uni.showModal({
				title: '提示',
				content: '確定要退出賬號嗎？',
				showCancel: true,
				success: res => {
					if (res.confirm) {
						console.log('用户点击确定')
						this.logoutForm()
					} else if (res.cancel) {
						console.log('用户点击取消')
					}
				}
			})
		},
		async logoutForm(){
			let res=await userLogout({})
			if(res.code==1){
				uni.setStorageSync('token','')
				uni.clearStorage()
				uni.reLaunch({ url: '/pages/user/userLogin' })
			}else{
				uni.showToast({
          icon:'none',
          title: res.msg||'系統異常'
        })
			}
		},
	}
};
</script>
<style lang="scss" scoped>
.personal-wrap{
	width: 100%;
	height: 100vh;
	overflow-y: scroll;
	background: #F4F6FA;
}
.user-top{
	width: 100%;
	height: 140px;
	background: url('/static/images/user/icon_u_t_bg.png') no-repeat;
	background-size: 100% 100%;
	position: relative;
}
.u-t-info{
	width: calc(100% - 30px);
	margin: 0 auto 0;
	padding-top: 30px;
	display: flex;
	justify-content: center;
	align-items: center;
}
.u-t-i-l{
	width: 58px;
	height: 58px;
	border-radius: 50%;
	img{
		width: 100%;
		height: 100%;
		border-radius: 50%;
	}
}
.u-t-i-c{
	width: calc(100% - 85px);
	margin: 0 10px;
	font-size: 13px;
	color: #666666;
	line-height: 18px;
	.i-name{
		font-weight: bolder;
		font-size: 18px;
		color: #333333;
		line-height: 25px;
		padding-bottom: 5px;
	}
}
.u-t-i-r{
	width: 7px;
	height: 12px;
	img{
		width: 100%;
		height: 100%;
	}
}
.u-t-btn{
	width: calc(100% - 20px);
	height: 46px;
	background: linear-gradient( 90deg, #0696F6 0%, #016FF1 100%);
	border-radius: 10px;
	color: #fff;
	font-weight: bold;
	font-size: 15px;
	color: #FFFFFF;
	position: absolute;
	left: 10px;
	bottom: -23px;
	display: flex;
	justify-content: center;
	align-items: center;
	.u-t-b-l{
		width: 22px;
		height: 22px;
		img{
			width: 100%;
			height: 100%;
		}
	}
	.u-t-b-c{
		width: calc(100% - 75px);
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin: 0 10px;
	}
	.u-t-b-r{
		width: 8px;
		height: 14px;
		img{
			width: 100%;
			height: 100%;
		}
	}
}
.online-info{
	width: calc(100% - 20px);
	padding: 13px 10px;
	border-radius: 10px;
	background: #fff;
	margin: 10px auto 10px;
}
.online-info.top{
	margin-top: 38px;
}
.file-title{
	display: flex;
	justify-content: space-between;
	align-items: center;
	font-weight: bold;
	font-size: 15px;
	color: #333333;
	line-height: 21px;
}
.f-t-l{
	width: calc(100% - 20px);
	display: flex;
	justify-content: flex-start;
	align-items: center;
	img{
		width: 20px;
		height: 20px;
		margin-right: 5px;
	}
}
.f-t-r{
	width: 16px;
	height: 16px;
	img{
		width: 100%;
		height: 100%;
	}
}
.icon_a_r.f-t-r{
	width: 7px;
	height: 12px;
	img{
		width: 100%;
		height: 100%;
	}
}
.file-no{
	font-size: 13px;
	color: #768396;
	line-height: 18px;
	text-align: center;
	img{
		width: 98px;
		height: 98px;
		display: block;
		margin: 13px auto 10px;
	}
}
.file-jl-no{
	width: 100%;
	height: 39px;
	border-radius: 10px;
	background: #F4F6FA;
	display: flex;
	justify-content: center;
	align-items: center;
	margin: 15px auto 0;
	font-size: 15px;
	color: #333333;
	line-height: 21px;
	img{
		width: 15px;
		height: 15px;
		margin-right: 5px;
	}
}
.login-btn{
	width: calc(100% - 20px);
	background: #FFFFFF;
	border-radius: 10px;
	font-weight: bold;
	font-size: 15px;
	color: #666666;
	line-height: 21px;
	padding: 12px 0;
	margin: 0 auto 20px;
	text-align: center;
}
.file-row-b{
	display: flex;
	justify-content: center;
	align-items: center;
	font-size: 12px;
	color: #666666;
	line-height: 17px;
	margin-top: 20px;
	img{
		width: 6px;
		height: 10px;
		margin-left: 7px;
	}
}
.file-row{
	display: flex;
	justify-content: flex-start;
	align-items: flex-start;
	margin-top: 15px;
	font-size: 14px;
	color: #333333;
	line-height: 20px;
	img{
		width: 18px;
		height: 15px;
		margin-right: 5px;
	}
	.file-r-item{
		flex: 1;
		display: flex;
		justify-content: flex-start;
		align-items: flex-start;
	}
	.f-r-i-l.file-r-item{
		flex: 1.5;
	}
}
.file-jl-li{
	background: #F4F6FA;
	border-radius: 10px;
	font-size: 15px;
	color: #333333;
	line-height: 21px;
	display: flex;
	justify-content: space-between;
	align-items: center;
	margin: 10px 0;
	padding: 10px;
	.f-j-l-l{
		display: flex;
		justify-content: flex-start;
		align-items: center;
		img{
			width: 29px;
			height: 29px;
			margin-right: 10px;
		}
	}
	img{
		width: 15px;
		height: 4px;
	}
}
.file-jl-li.top{
	margin-top: 15px;
}
</style>
